/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package PaqueteServelt;

import cl.tienda.modelo.Producto;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Jano_dx
 */
@SuppressWarnings("UseOfObsoleteCollectionType")
public class ServletEAgrProducto1 extends HttpServlet {
   
    
   
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        doPost(request, response);
    } 

   
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
         //Para mostrar la pagina Web
        PrintWriter out=response.getWriter();
        //Obtengo todos los datos de la sesion de usuario
        Vector<Producto> productos=(Vector<Producto>)request.getSession().getAttribute("productos");

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Consultar Producto</title>");
        out.println("<style type=\"text/css\">");
        out.println("<!--");
        out.println("body {");
        out.println("background-color: #FFFF99;");
        out.println("}");
        out.println("body,td,th {");
        out.println("font-family: Arial, Helvetica, sans-serif;");
        out.println("}");
        out.println("</style>");
        out.println("</head>");
        out.println("<body>");
        out.println("<table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
        out.println("<tr>");
        out.println("<td width=\"84\" bgcolor=\"#FF0000\"><img src=\"img/carritorx8[1].jpg\" width=\"84\" height=\"77\" /></td>");
        out.println("<td width=\"716\" bgcolor=\"#FF0000\"><h1 style=\"color:#FFFFFF\">Carrito de Compas con Vectores y Sesiones</h1></td>");
        out.println("</tr>");
        out.println("<tr align=\"center\">");
        out.println("<td colspan=\"2\">&nbsp;</td>");
        out.println("</tr>");
        out.println("<tr align=\"center\">");
        out.println("<td colspan=\"2\">");
        out.println("<h4><a href=\"ServletCConProd\">Consultar Productos</a> | <a href=\"ServletEAgrProducto1\">Actualizar Stock</a> | <a href=\"login.html\">Salir</a></h4></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td colspan=\"2\">&nbsp;</td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td colspan=\"2\"><table width=\"100%\" border=\"0\">");
        out.println("<tr bgcolor=\"#FF6600\" style=\"color: #FFFFFF\">");
        out.println("<td width=\"52%\"><h4>Nombre</h4></td>");
        out.println("<td width=\"16%\" align=\"right\" valign=\"top\"><h4><span class=\"Estilo3\">Stock</span></h4></td>");
        out.println("<td width=\"16%\" align=\"right\" valign=\"top\"><h4><span class=\"Estilo3\">Precio</span></h4></td>");
        out.println("<td width=\"16%\" align=\"right\" valign=\"top\"><h4><span class=\"Estilo3\">Proceso</span></h4></td>");
        out.println("</tr>");

        //Vamos a mostrar la lista de productos del vector de Productos

        for(int i=0; i<productos.size(); i++){
            if(i%2==0){
                out.println("<tr bgcolor=\"#FFFFFF\">");
                out.println("<td>" + productos.get(i).getNombreProducto() + "</td>");
                out.println("<td align=\"right\" valign=\"top\">"+ productos.get(i).getStock() +"</td>");
                out.println("<td align=\"right\" valign=\"top\">"+ productos.get(i).getPrecio() +"</td>");
                out.println("<td align=\"right\" valign=\"top\"><a href=\"ServletEAgrProducto2?indice=" + i + " \">Agregar</a></td>");
                out.println("</tr>");
            }else{
                out.println("<tr>");
                out.println("<td>" + productos.get(i).getNombreProducto() + "</td>");
                out.println("<td align=\"right\" valign=\"top\">"+ productos.get(i).getStock() +"</td>");
                out.println("<td align=\"right\" valign=\"top\">"+ productos.get(i).getPrecio() +"</td>");
                out.println("<td align=\"right\" valign=\"top\"><a href=\"ServletEAgrProducto2?indice=" + i + " \">Agregar</a></td>");
                out.println("</tr>");
            }
        }

        out.println("</table></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td colspan=\"2\">&nbsp;</td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</body>");
        out.println("</html>");

        out.close();
    }

   
    @Override
    public String getServletInfo() {
        return "Short description";
    }

}
